<?php
/**
* This file handles the LDAP operation for Novell E-Directory
*
* @package Ldap
* @subpackage NovellEDirectory
*/

/**
* Include the base ldap class.
*/
require_once(dirname(__FILE__).'/Ldap.php');
class NovellEDirectory extends Ldap
{
	/**
	* NovellEDirectory
	* Constructor for NovellEDirectory class
	*
	* @param String		$ldapHost 		LDAP Server Host (hostname or ip address)
	* @param Integer	$ldapPort 		LDAP Server Port
	* @param String		$username 		LDAP Connect Username - Authorized User to connect to LDAP Server
	* @param String		$password 		Password for Connect Username
	* @param String		$baseDn 		The Base DN where our LDAP will operate from
	* @param Boolean	$ldapVersion3 	The Indication flag whether this LDAP Connection is using LDAP Version 3 connection.
	* @param Boolean 	$negotiateTLS 	The Indication flag whether this LDAP Connection is using TLS Negotiation.
	* @param Integer	$followReferral The option for Referral for this LDAP Connection
	*
	* @return Mixed		return not success return null 
	*/
	function NovellEDirectory ($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral)
	{
		parent::Ldap($ldapHost, $ldapPort, $username, $password, $baseDn , $ldapVersion3, $negotiateTLS, $followReferral);
	}

	/**
	* setAccountStatus
	* Set the account status for an entry in LDAP
	*
	* @param String		$dn			Distinguish name - unique name for ldap entry	
	* @param Boolean	$enableFlg	if true, the status will be set to Active. Otherwise, the status will be set as Disable
	* @param Booean		$userCurrentStatus	Current status of the user
	*
	* @return Boolean	return the update status
	*/
	function setAccountStatus ($dn, $enableFlg, $userCurrentStatus) {
		$status = 'TRUE';
		if ($enableFlg) {
			$status = 'FALSE';
		}
		$statusAttribute = array($this->getAccountStatusAttribute=>$status);
		if(!$GLOBALS['AKB_LDAP']-> modify($dn, $statusAttribute)) {
			return false;
		}
		return true;
	}

	/**
	* getAccountStatus
	* Get the status from the specified LDAP entry
	*
	* @param	String		$searchString		Filter criteria - used for query the ldap entries	
	*
	* @return	Array		if there is a result, return the result in array form. Otherwise, return an empty array
	*/
	function getAccountStatus ($searchString)
	{
		return $this->search($searchString, array($this->getAccountStatusAttribute()));
	}

	/**
	* isStatusEnable
	* To check if the returned status is Enable or Disable
	*
	* @param	Mixed		$status		The account status return from LDAP server
	*
	* @return	Boolean		If the user's account is enable or disable
	*/
	function isStatusEnable($status)
	{
		if (strtolower($status) == 'true') {
			return false;
		}
		return true;
	}
	/**
	* getAccountStatusAttribute
	* Get the Attribute name that hold the user account status
	*
	* @see getAccountStatus
	* @see setAccountStatus
	* 
	* @return	String	Return the attribute of user account status
	*/
	function getAccountStatusAttribute() {
		return 'logindisabled';
	}

}


?>